package 力扣日常刷题.木23一月.第09天309;

import java.util.ArrayList;

/**
 * @author 帅小伙
 * @date 2022/3/9
 * @description
 */
public class Demo31和为s的连续正数序列 {


    public static void main(String[] args) {
        findContinuousSequence(15);
    }

    public static int[][] findContinuousSequence(int target) {
        int l = 1,r = 2;
        ArrayList<int[]> ans = new ArrayList<>();

        while(l < r) {
            // l - r   的个数是    r - l + 1
            int sum = (r + l) * (r - l + 1) / 2;
            if(sum == target) {
                int[] arr = new int[r - l + 1];
                for (int i = l; i <= r; i++) {
                    arr[i - l] = i;
                }
                ans.add(arr);
                l++;
            }else if(sum > target){
                r++;
            }else {
                l++;
            }
        }
        return ans.toArray(new int[ans.size()][]);



    }
}
